home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c,comp.std.c
- Subject: Re: atexit() internals under Unix
- Date: Sat, 16 Mar 96 21:21:58 GMT
- Organization: none
- Distribution: world
- Message-ID: <827011318snz@genesis.demon.co.uk>
- References: <4icqbm$pk9@fnnews.fnal.gov>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4icqbm$pk9@fnnews.fnal.gov> berg@fsui01.fnal.gov "David Berg" writes:
-
- >I have a some questions regarding ANSI C in a Unix (or POSIX) context.
- >They all relate to exit handling. I don't have a copy of the ANSI C
- >standard, nor have I been able to find more than cursory explanations
- >in other reference sources.
- >
- >1. Suppose a process registers an exit handler with atexit(). The exit
- > handler, in turn, calls some application library routines, which call
- > others that are also called from the mainline of the program. Leaving
- > the issue of re-entrancy aside, is there any general way (eg, a system
- > service call) by which the function can determine that it was called
- > in the context of an exit handler?
-
- No, but this is easy to determine using an auxiliary/wrapper function.
- Register the wrapper function which sets a status flag or calls the
- work function with a suitable argument.
-
- > Can it access the exit status with which exit() was called?
-
- No.
-
- >2. Same as above, except the process registers a signal handler with
- > sigaction(). Can a lower level function determine that it was called
- > in the context of a signal handler?
-
- Not as far as I am aware. This is a question for comp.unix.programmer.
-
- >What if the signal handler calls exit()?
-
- That is illegal where the signal was generated from an asynchronous
- event (i.e. other than through calling raise() or abort()). Where legal
- exit() acts just as it does when called outside a signal handler.
-
- >3. Suppose the process now forks. From experimentation, it appears that
- > exit handlers, like signal handlers, are inherited by the child. Is
- > this behavior standard (though beyond the scope of ANSI), or at least
- > conventional?
-
- The handlers are inherited, pending signals are not. Again this is a
- topic for comp.unix.programmer.
-
- >4. If an exit handler calls exit(), is the handler called recursively? Or
- > has it been unregistered before it is invoked? (Again, it would appear
- > from experimentation that it is indeed unregistered.)
-
- It is illegal (i.e. results in undefined behaviour) for a program to call
- exit() more than once.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-